#include "IOCTLSerializer.h"

NTSTATUS DispatchIOCTL(
    __in PDEVICE_OBJECT fido,
    __in PIRP Irp
)
{
    IOCTLSerializer ioctlSerializer;

    PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
    ////////////////////////////////////////////////////////////////////////////////////
    NTSTATUS status = IoAcquireRemoveLock(&pdx->RemoveLock, Irp);
    if (!NT_SUCCESS(status))
    {
        return CompleteRequest(Irp, status, 0);
    }
    ////////////////////////////////////////////////////////////////////////////////////
    PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
    ULONG ioctl = stack->Parameters.DeviceIoControl.IoControlCode;


    //ULONG bytesWrote = ioctlSerializer.SerializeIOCTL(Irp, pBuffer, bufferSize, FALSE);


    IoSkipCurrentIrpStackLocation(Irp);
    status = IoCallDriver(pdx->LowerDeviceObject, Irp);
    IoReleaseRemoveLock(&pdx->RemoveLock, Irp);

    return status;
}